﻿namespace Oddo.Concept.Crm.Server.Repositoy.Module
{
    using System.Web.Http.SelfHost;
    using Microsoft.Practices.Unity;
    using Microsoft.Practices.Unity.InterceptionExtension;
    using Oddo.Concept.Crm.Common.Behaviors;
    using Oddo.Concept.Crm.Common.Modules;
    using Oddo.Concept.Crm.Repository.Common.Contracts;
    using Oddo.Concept.Crm.Server.Repository.Business;
    using Oddo.Concept.Crm.Server.Repository.Controller;
    using Oddo.Concept.Crm.Server.Repository.DataAccess;
    using Oddo.Concept.Crm.Server.Repository.Services;

    public class RepositoryModule : ServerModuleBase
    {
        public override void RegisterTypes(IUnityContainer container)
        {
            container.RegisterType<IRepositoryServices, RepositoryServicesProvider>(new ContainerControlledLifetimeManager(), new Interceptor<InterfaceInterceptor>(), new InterceptionBehavior<TransactionBehavior>(), new InterceptionBehavior<MethodCallTraceBehavior>());
            container.RegisterType<ICountryBusiness, CountryBusiness>(new ContainerControlledLifetimeManager(), new Interceptor<InterfaceInterceptor>(), new InterceptionBehavior<MethodCallTraceBehavior>());
            container.RegisterType<ICountryDataAccess, CountryDataAccess>(new ContainerControlledLifetimeManager(), new Interceptor<InterfaceInterceptor>(), new InterceptionBehavior<MethodCallTraceBehavior>());
            container.RegisterType<RepositoryServicesController>(new TransientLifetimeManager());
            
            var conf = container.Resolve<HttpSelfHostConfiguration>();
            var controller = container.Resolve<RepositoryServicesController>();
            controller.RegisterRoutes(conf.Routes);
            controller.Dispose();
        }
    }
}